﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Communication.Net.Web;

namespace UtilZ.Tool.HostCore
{
    internal class WebSocketClientCollection : ICollection<WebSocketClient>, ICollection, IDisposable
    {
        private readonly object _syncRoot = new object();
        private readonly List<WebSocketClient> _clients = new List<WebSocketClient>();

        public WebSocketClientCollection()
        {

        }


        public int Count
        {
            get
            {
                lock (this._syncRoot)
                {
                    return this._clients.Count;
                }
            }
        }

        public bool IsSynchronized
        {
            get { return true; }
        }

        public object SyncRoot
        {
            get { return this._syncRoot; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public void Add(WebSocketClient item)
        {
            lock (this._syncRoot)
            {
                this._clients.Add(item);
            }
        }

        public bool Remove(WebSocketClient item)
        {
            lock (this._syncRoot)
            {
                return this._clients.Remove(item);
            }
        }

        public void Clear()
        {
            lock (this._syncRoot)
            {
                this._clients.Clear();
            }
        }

        public bool Contains(WebSocketClient item)
        {
            lock (this._syncRoot)
            {
                return this._clients.Contains(item);
            }
        }

        public void CopyTo(Array array, int index)
        {
            throw new NotSupportedException();
        }

        public void CopyTo(WebSocketClient[] array, int arrayIndex)
        {
            lock (this._syncRoot)
            {
                this._clients.CopyTo(array, arrayIndex);
            }
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        public IEnumerator GetEnumerator()
        {
            return this._clients.GetEnumerator();
        }



        IEnumerator<WebSocketClient> IEnumerable<WebSocketClient>.GetEnumerator()
        {
            return this._clients.GetEnumerator();
        }
    }
}
